package com.talentgame.tankspk.GameCore;

import android.view.accessibility.CaptioningManager;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;

/**
 * Created by 54560 on 2016/12/20.
 * 跟随着玩家的主摄像机
 */
public class FollowPlayerCam {
    public GameObject target;
    PerspectiveCamera Cam;
    private final Vector3 offsetVectovr = new Vector3(0,2,-8);
    //private final Vector3 offsetVectovr = new Vector3(5,2.5f,0);
    public FollowPlayerCam()
    {
        Cam = new PerspectiveCamera(60, Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
        Cam.lookAt(new Vector3(0,0,0));
        Cam.position.set(0,2.5f,-5);
        Cam.rotate(180,0,1,0);
        Cam.rotate(0,1,0,0);
        Cam.near = 1;
        Cam.far=3000;

        //transform.setToTranslation(Cam.position);
        //transform.setToRotation(new Vector3(0,-1,0),180);
        Cam.update();
    }
    public void LookTarget(GameObject go)
    {
        this.target = go;
    }
    void update(float detaltime)
    {
        //计算观察后摄像机的位置
        if(target == null)return;
        Vector3 targetPosition = new Vector3();
        target.transform.getTranslation(targetPosition);
        Cam.position.set(targetPosition.add(offsetVectovr));
        Cam.update();
    }
}
